"""
utility functions
"""

import os
import os.path as osp

def absfile( filename, resolveLinks=1 ):
    """
    Get absolute file path::
      - expand ~ to user home, change
      - expand ../../ to absolute path
      - resolve links

    @param filename: name of file
    @type  filename: str
    @param resolveLinks: eliminate any symbolic links (default: 1)
    @type  resolveLinks: 1|0
    
    @return: absolute path or filename
    @rtype: string
    """
    if not filename:
        return filename
    r = osp.abspath( osp.expanduser( filename ) )
    if resolveLinks:
        r = osp.realpath( r )
    return r

def projectRoot():
    """
    Root of labware project.
    
    @return: absolute path of the root of current project::
             i.e. '/home/raik/labware'
    @rtype: str
    """
    ## import this module
    import tools
    ## get location of this module
    f = absfile(tools.__file__)
    ## extract path and assume it is 'project_root/Labware'
    f = osp.split( f )[0] + '/../'
    return absfile( f )


def testRoot():
    """
    Root of Biskit test directory.

    @return: absolute path
    @rtype: str    
    """
    return projectRoot() + '/test'
